package com.ftg.learn.chapter13;

import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * 测试 二维数据 多元素 统计问题
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/2/16 下午1:27
 */
public class LearnStream04 {

    public static void main(String[] args) {
        int[][] as = new int[][]{{1,2,3},{4,5,6},{1,3}};
        //函数调用
        System.out.println(Arrays.stream(as).flatMapToInt(Arrays::stream).filter(y -> y > 2).count());
        //转换
        System.out.println(Arrays.stream(as).flatMapToInt(x -> Arrays.stream(x)).filter(y -> y > 2).count());
        //自行编写处理方法
        System.out.println(Arrays.stream(as).flatMap(x -> {
            //Builder 构建者
            Stream.Builder builder = Stream.builder();
            for (int i : x) {
                builder.add(i);
            }
            return builder.build();
        }).filter(y -> {
            int x = (int) y;
            return x > 2;
        }).count());

//        public interface Collector<T, A, R> {
//        Supplier<A> supplier();


//
//        System.out.println(Arrays.stream(as).map(new Function<int[], Object>() {
//            @Override
//            public Object apply(int[] ints) {
//                for (int anInt : ints) {
//                    if(anInt > 2){
//                        return anInt;
//                    }
//                    continue;
//                }
//                return null;
//            }
//        }).count());
    }

}
